package offer;

import java.util.ArrayList;
import java.util.List;

public class Solution57_II {
    public int[][] findContinuousSequence(int target) {
        List<int[]> res = new ArrayList<>();
        int i = 1, j = 2, sum = 3;
        while (j <= target / 2 + 1) {
            if (sum == target) {
                int[] a = new int[j - i + 1];
                for (int k = i; k <= j; k++) {
                    a[k - i] = k;
                }
                res.add(a);
                j++;
                sum += j;
            } else if (sum < target) {
                j++;
                sum += j;
            } else {
                sum -= i;
                i++;
            }
        }
        return res.toArray(new int[0][]);
    }
}
